#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''=================================================
@Project -> File   ：db-toolkit -> config
@IDE    ：PyCharm
@Author ：Json
@Date   ：2025/3/24 11:55
@Desc   ：
=================================================='''

# config.py
import os
import json
from pathlib import Path
from typing import Dict, Any


class DBConfig:
    _config: Dict[str, Any] = None

    @classmethod
    def load(cls, config_path: str = None, database_name: str = None):
        cls._config = {}
        if not config_path:
            dir_path = os.path.dirname(os.path.abspath(__file__))
            # 将目录路径和文件名组合起来
            config_path = os.path.join(dir_path, 'db_config.json')
        with open(config_path) as f:
            file_config = json.load(f)
            cls._config.update({k: v for k, v in file_config.items() if v})
        if database_name:
            cls._config['database'] = database_name
        return cls._config
